package ruxi.tema1;

import java.util.ArrayList;

import android.app.Activity;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ForecastAdapter extends BaseAdapter {
	private Activity context;
	ArrayList<Weather> prognoze;
	
	public ForecastAdapter(Activity _context) {
		super();
		this.context = _context;
		this.prognoze = new ArrayList<Weather>();
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return prognoze.size();
	}

	@Override
	public Object getItem(int position) {
		
		return prognoze.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View element;
		 
	    LayoutInflater inflater = context.getLayoutInflater();
	    Weather prognoza = prognoze.get(position);
	    //vad pe care din layout-uri trebuie sa il pun
	    if(prognoza.isToday) {
	    	element = inflater.inflate(R.layout.today, null);
	    	
	    	TextView date = (TextView) element.findViewById(R.id.date);
	    	date.setText("Today (" + prognoza.date.toString() + ")");
	    	
	    	ImageView icon = (ImageView) element.findViewById(R.id.icon);
	    	Resources res = context.getResources();
	    	int imgid = res.getIdentifier(prognoza.icon, "drawable", context.getPackageName());
	    	icon.setImageResource(imgid);
	    	
	    	TextView conditions = (TextView)element.findViewById(R.id.conditions);
	    	conditions.setText(prognoza.condition);
	    	
	    	TextView humidity = (TextView) element.findViewById(R.id.humidity);
	    	humidity.setText(prognoza.humidity);
	    	
	    	TextView wind = (TextView) element.findViewById(R.id.wind);
	    	wind.setText(prognoza.windCond);
	    	
	    	TextView temp = (TextView) element.findViewById(R.id.temperature);
	    	temp.setText("Temperature: " + prognoza.temp + (char) 0x00B0 + "C");
	    	
	    }
	    else{ 
	    	element = inflater.inflate(R.layout.forecastitem, null);
	    	
	    	ImageView icon = (ImageView) element.findViewById(R.id.icon1);
	    	Resources res = context.getResources();
	    	int imgid = res.getIdentifier(prognoza.icon, "drawable", context.getPackageName());
	    	icon.setImageResource(imgid);
	    	
	    	
	    
	    	TextView low = (TextView) element.findViewById(R.id.low);
	    	low.setText(prognoza.lowT.toString() + (char) 0x00B0 + "C");
	    	
	    	
	    	TextView day = (TextView) element.findViewById(R.id.day);
	    	day.setText(prognoza.day);
	    	
	    	TextView conditions = (TextView)element.findViewById(R.id.condition);
	    	conditions.setText(prognoza.condition);
	    }
	    
	    
	    
		return element;
	}

}
